<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
</head>

<body>
  <div id="app">
    <com1></com1>
    <com2></com2>

  </div>
  <script src="./js/vue.js"></script>
  <script>
    var bus = new Vue()
    Vue.component('com1', {
      data: function () {
        return {
          name: '张三',
          age: 0,
        }
      },
      template: `
        <div>
          <p>{{name}}</p>  
          <p>{{age}}</p> 
          <button @click='handel'>李四+1</button> 
        </div>
      `,
      methods: {
        handel() {
          bus.$emit('lisi')
        }
      },
      mounted() {
        bus.$on('zhangsan', () => {
          this.age++
        })
      }
    })

    Vue.component('com2', {
      data: function () {
        return {
          name: '李四',
          age: 0,
        }
      },
      template: `
        <div>
          <p>{{name}}</p>  
          <p>{{age}}</p> 
          <button @click='handel'>张三+1</button> 
        </div>
      `,
      methods: {
        handel() {
          bus.$emit('zhangsan')
        }
      },
      mounted() {
        bus.$on('lisi', () => {
          this.age++
        })
      }
    })
    var vm = new Vue({
      el: '#app',
      data: {}
    })
  </script>
</body>

</html>